import java.util.Scanner;

public class Main {
    //按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4)    （递归）
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ret(n);
    }
    public static void ret(int n) {
        if(n > 9) {
            ret(n / 10);
        }
        System.out.println(n % 10);
    }

    //写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int add(int n) {
        if(n < 9){
            return n;
        }
        return n % 10 + add(n / 10);
    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n =  scanner.nextInt();
        System.out.println(add(n));
    }

    //递归求斐波那契数列的第 N 项
    public static int fac(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }

        return fac(n - 1) + fac(n - 2);
    }
    public static void main3(String[] args) {
        Scanner fac = new Scanner(System.in);
        int n = fac.nextInt();
        System.out.println(fac(n));
    }

    //递归求解汉诺塔问题
    public static void hannio(int n, char x , char y , char z) {
        if(n == 1) {
            System.out.println("Move " + n + " from " + x + " to " + z);
        }else {
            hannio(n - 1, x , z , y);
            System.out.println("Move " + n + " from " + x + " to " + z);
            hannio(n - 1, y , z , x);
        }
    }

    public static void main4(String[] args) {
        int n = 3;
        char x;
        char y;
        char z;
        hannio(n, 'x', 'y','z' );
    }

    //递归求 N 的阶乘
    public static int qrt(int n) {
        if(n == 1) {
            return 1;
        }
        return n * qrt(n - 1);
    }

    public static void main5(String[] args) {
        int n = 3;
        System.out.println(qrt(3));
    }

    //递归求 1 + 2 + 3 + ... + 10
    public static int sum(int n) {
        if(n == 1) {
            return 1;
        }
        return sum(n - 1) + n;
    }

    public static void main6(String[] args) {
        int n = 4;
        System.out.println(sum(n));
    }

    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
    public static int max(int x, int y) {
        int c = x > y ? x : y;
        return c;
    }
    public static int max(int n , int b ,int c) {
        int tmp = max(n,b);
        return max(tmp,c);
    }

    public static void main7(String[] args) {
        int a = 10;
        int b = 20;
        int c = 30;
        System.out.println(max(a,b));
        System.out.println(max(a,b,c));
    }

    //求1！+2！+3！+4！+........+n!的和
    public static int jc(int n) {
        if(n == 1) {
            return 1;
        }
        return n * jc(n - 1);
    }

    public static void main8(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 0;
        int sum = 0;
        for( i = 1; i <= n ; i++ ) {
            sum += jc(i);
        }
        System.out.println(sum);
    }
}